export function setUserInfo(data: any) {
    uni.setStorageSync('USER_INFO', data)
}

export function getUserInfo() {
    return uni.getStorageSync('USER_INFO') || {}
}

export function getToken() {
    return uni.getStorageSync('TOKEN') || ''
}

export function setToken(token: string) {
    uni.setStorageSync('TOKEN', token)
}

export function getLoginStatus() {
    return Boolean(getUserInfo() && getToken())
}

/**
 * 根据身份证号获取性别
 * @param idNum
 */
export function getGender(idNum: string) {
    // console.log(idNum)
    if (idNum.length !== 18) {
        throw new Error('传入的不是18位身份证号');
    }
    const id = parseInt(idNum.charAt(16), 10)
    return id % 2 == 0 ? 0 : 1
}

// 传入身份证然后格式化为1111***1111
export function formatIdNum(idNum: string, start: number = 4, aa: number = 14) {
    return idNum.slice(0, start) + '****' + idNum.slice(aa)
}